

C_PATH=$PWD
SDK_PATH="${PWD%/*/*}"
TARGET_PATH=$SDK_PATH/buildroot/output/rockchip_rk3506/target

mkdir -p build
echo $C_PATH
echo $SDK_PATH
echo $TARGET_PATH



main()
{
    if [ "$1" = "config" ]; then
        _config
    elif [ "$1" = "make" ]; then
        _make
    elif [ "$1" = "install" ]; then
        _install 
	fi
    
}


#编译
_make()
{
    make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- -j$(nproc)
    make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- -j$(nproc) modules
    
}

_config()
{
    export PATH=$SDK_PATH/prebuilts/gcc/linux-x86/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin:$PATH
    ./bootstrap
    ./configure --prefix=$TARGET_PATH --host=arm-none-linux-gnueabihf --with-linux-dir=$SDK_PATH/kernel --enable-8139too=no --enable-dwmac-rk=yes --enable-generic=no --enable-wildcards=yes
}


_install()
{
    make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- install systemdsystemunitdir=$TARGET_PATH/usr/lib/systemd/system
    #安装内核模块到指定安装目录
    make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- INSTALL_MOD_PATH=$TARGET_PATH modules_install

}
main $1
